package com.qfedu.microcheck.rjx.check.controller;

import com.qfedu.common.core.annotation.NoLogin;
import com.qfedu.common.core.common.R;
import com.qfedu.microcheck.rjx.check.service.CheckService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.Map;

/**
 * ---just do it---
 *
 * @author ren
 * @date 2025/10/14
 * @desc
 */

@RestController
@RequestMapping("/api/attendance")
public class SignController {
    @Resource
    CheckService checkService;

    /**
     * 打卡签到
     * params  clockType--1:签到 2:签退
     * @return
     */
    @NoLogin
    @PostMapping("/on-work")
    public R checkIn(@RequestBody Map<String, Object> params) {
        Integer clockType = (Integer) params.get("clockType");

        String typeName = "";
        if (clockType == 1) {
            typeName = "签到";
            // 调用打卡接口
            checkService.sign(1);
        } else if (clockType == 2) {
            typeName = "签退";
        } else {
            typeName = "未知类型";
        }

        System.out.println("打卡签到类型：" + typeName + " (类型码：" + clockType + ")");
        return R.success("打卡" + typeName);
    }

    /**
     * 打卡签退
     * @return 签退状态--早退还是正常
     */
    @RequestMapping("/off-work")
    public R checkOut() {
        System.out.println("打卡签退");
        // 调用打卡接口
        checkService.sign(2);
        return R.success("打卡签退");
    }



}
